version 14.2
set more off
set matsize 11000

***********************************************************************************************************************
* THIS ROUTINE GENERATES FIGURE A.IX OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* ALL FIRMS */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>1996 & fy<=2003
g						ind=real(substr(item_cd,1,4))
run						"$project_do\Industry PCT and Description" ind
/*g						one=1
bys						regno:egen nreturns=sum(one)
qui						sum nreturns
keep					if nreturns==r(max)*/
keep                	if business_sts=="1" | business_sts=="2"
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=1999)
g						treat_after=treat*after						
g						lnsales=log(domsale_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=1997/2003 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* BASELINE SPECIFICATION */

g						btreatafter=0
g						setreatafter=0
g						btreatafter2=0
g						setreatafter2=0
g						btreat98=0
g						setreat98=0
forvalues				ind=1/21 {
cap 					drop include
g 						include=(indpct==`ind' & treat==1 | treat==0)
qui						areg lnsales pdum2-pdum84 treat treat_after if include==1, absorb(regnor) cluster(regnor)
replace					btreatafter=_b[treat_after] if indpct==`ind'
replace					setreatafter=_se[treat_after] if indpct==`ind'
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after if include==1, absorb(regnor) cluster(regnor)
replace					btreatafter2=_b[treat_after] if indpct==`ind'
replace					setreatafter2=_se[treat_after] if indpct==`ind'
replace					btreat98=_b[treat_1998] if indpct==`ind'
replace					setreat98=_se[treat_1998] if indpct==`ind'
}
duplicates				drop indpct, force
drop					if indpct==1 | indpct==2 | indpct==3 | indpct==5
qui						sum indpct
replace					indpct=indpct-r(min)+1
keep					indpct inddesc btreatafter- setreat98 				
g						treatafter_l=btreatafter-1.96*setreatafter
g						treatafter_u=btreatafter+1.96*setreatafter
g						treatafter2_l=btreatafter2-1.96*setreatafter2
g						treatafter2_u=btreatafter2+1.96*setreatafter2
g						treat98_l=btreat98-1.96*setreat98
g						treat98_u=btreat98+1.96*setreat98
sort					indpct
g						indpct2=_n
#d						;
twoway					rcap treatafter_l treatafter_u indpct2, lcolor(red) lwidth(thick)   
						ytitle(Coefficient)  ylabel(-2 -1 0 0.48 1 2) xtitle(Industry) xlabel(1(1)17)
						yline(0.481, lstyle(foreground) lwidth(thick))
						yline(0, lstyle(foreground) lwidth(thin) lpattern(shortdash))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 0)) bgcolor(white);
graph 					export "$project_output\IntMarginByIndustry.eps", replace;
#d						cr
#d						;
twoway					rcap treat98_l treat98_u indpct2, lcolor(red) lwidth(thick)   
						ytitle(Coefficient) ylabel(-2 -1 0 0.48 1 2) xtitle(Industry) xlabel(1(1)17)
						yline(0.481, lstyle(foreground) lwidth(thick))
						yline(0, lstyle(foreground) lwidth(thin) lpattern(shortdash))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 0)) bgcolor(white);
graph 					export "$project_output\IntMarginByIndustry_Placebo.eps", replace;
#d						cr

/* PLACEBO */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
keep					if fy>2003 & fy<=2010
g						ind=real(substr(item_cd,1,4))
run						"$project_do\Industry PCT and Description" ind
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=2006)
g						treat_after=treat*after						
g						lnsales=log(domsale_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=2004/2010 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 1 */

local					i=8
local					j=1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(regnor)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)
g						btreatafter=0
g						setreatafter=0
g						btreatafter2=0
g						setreatafter2=0
g						btreat05=0
g						setreat05=0
forvalues				ind=1/21 {
cap 					drop include
g 						include=(indpct==`ind' & treat==1 | treat==0)
qui						areg lnsales pdum2-pdum84 treat treat_after if include==1, absorb(regnor) cluster(regnor)
replace					btreatafter=_b[treat_after] if indpct==`ind'
replace					setreatafter=_se[treat_after] if indpct==`ind'
qui						areg lnsales pdum2-pdum84 treat treat_2005 treat_after if include==1, absorb(regnor) cluster(regnor)
replace					btreatafter2=_b[treat_after] if indpct==`ind'
replace					setreatafter2=_se[treat_after] if indpct==`ind'
replace					btreat05=_b[treat_2005] if indpct==`ind'
replace					setreat05=_se[treat_2005] if indpct==`ind'
}
duplicates				drop indpct, force
drop					if indpct==1 | indpct==2 | indpct==3 | indpct==5
qui						sum indpct
replace					indpct=indpct-r(min)+1
keep					indpct inddesc btreatafter- setreat05 				
g						treatafter_l=btreatafter-1.96*setreatafter
g						treatafter_u=btreatafter+1.96*setreatafter
g						treatafter2_l=btreatafter2-1.96*setreatafter2
g						treatafter2_u=btreatafter2+1.96*setreatafter2
g						treat05_l=btreat05-1.96*setreat05
g						treat05_u=btreat05+1.96*setreat05
sort					indpct
g						indpct2=_n
#d						;
twoway					rcap treatafter_l treatafter_u indpct2, lcolor(red) lwidth(thick)   
						ytitle(Coefficient)  ylabel(-2 -1 0 0.48 1 2) xtitle(Industry) xlabel(1(1)17)
						yline(0.481, lstyle(foreground) lwidth(thick))
						yline(0, lstyle(foreground) lwidth(thin) lpattern(shortdash))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 0)) bgcolor(white);
graph 					export "$project_output\IntMarginByIndustry_Placebo2.eps", replace;
#d						cr
#d						;
twoway					rcap treat05_l treat05_u indpct2, lcolor(red) lwidth(thick)   
						ytitle(Coefficient) ylabel(-2 -1 0 0.48 1 2) xtitle(Industry) xlabel(1(1)17)
						yline(0.481, lstyle(foreground) lwidth(thick))
						yline(0, lstyle(foreground) lwidth(thin) lpattern(shortdash))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 0)) bgcolor(white);
graph 					export "$project_output\IntMarginByIndustry_Placebo_p2.eps", replace;
#d						cr

